package com.cn.redis2.dao;

import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.stereotype.Repository;

/**
 * @author Han
 */
@Repository
public class IncrDao extends BaseRedisDao<String, Long>{
	public Long incr(Integer paperId){
		return hashOperations.increment("incrkey", paperId, 1L);
	}
	public Long get(final Integer paperId){
		return execute(new RedisCallback<Long>() {

			@Override
			public Long doInRedis(RedisConnection connection) throws DataAccessException {
				byte [] bts = connection.hGet(getStringSerializer().serialize("incrkey"), getDefaultSerializer().serialize(paperId));
				return Long.parseLong(getStringSerializer().deserialize(bts));
			}
			
		});
	}
}